package cbcrypt

import (
	"fmt"
	"golang.org/x/crypto/bcrypt"
)

// 加密字符串
func Make(value string) string {
	hash, err := bcrypt.GenerateFromPassword([]byte(value), bcrypt.DefaultCost)
	if err != nil {
		fmt.Println(err)
	}

	encodeValue := string(hash)
	return encodeValue
}

// 检测字符串
func CheckEncode(encodeValue string, value string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(encodeValue), []byte(value))
	if err != nil {
		fmt.Println(encodeValue)
		return false
	}
	return true
}
